package com.pay.service.impl;

import com.pay.mapper.UserMapper;
import com.pay.pojo.User;
import com.pay.service.AccountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AccountImpl implements AccountService {

    @Resource
    private UserMapper userMapper;

    @Override
    public void createAccount(User user) {
       userMapper.insertUser(user);
    }

    @Override
    public Map<Object,Object> loginAccount(User user) {
        List<User> userInfo = userMapper.selectUserByEmail(user.getEmail());
        Map<Object,Object> resultMap = new HashMap<>();
        User userFirst = userInfo.get(0);
        if(!user.getPassword().equals(userFirst.getPassword())){
            resultMap.put("code", 400);
            resultMap.put("message", "登录失败，请重试!");
            return resultMap;
        }
        resultMap.put("code", 200);
        resultMap.put("message", "登录成功!");
        return resultMap;
    }
}
